<?

// Only allow 1 second execution time.
set_time_limit(1);


// Start a session.
session_start();


// PHP error reporting level
error_reporting(E_ALL);


// ------------------------------------------------------------ Auto Loader


function __autoload($class) {
    // Autoload Propel classes
    if ('Propel' == $class) {
        require_once 'propel/Propel.php';
        Propel::setLogger(LoggerManager::getLogger("Propel"));
        Propel::init("_application/resource/php-melange-conf.php");
    } elseif ('_Content' == $class) {
        include_once 'cms/content/Content.php';
    } elseif ('_Core' == $class) {
        include_once 'cms/core/Core.php';
    }
}


// ---------------------------------------------------------------- Context


// Import framework class
require_once("_library/framework/Context.php");


// Initialize framework
$context = new Context(
    dirname(__FILE__), // The context basepath ( path to the webroot )
    "/admin"           // The context path under which this context runs
);


// Set log file location
$context->setInitParameter("LOGPATH", "/tmp/php-melange.log");


// Set logger level (DEBUG|INFO|ERROR)
$context->setInitParameter("LOGLEVEL", "DEBUG");


// Set log file location
$context->setInitParameter("USE_CACHE", false);


// Set the cache exclude uris
$context->setInitParameter("CACHE_EXCLUDES", array("/login"));


// Initialize this context.
$context->init();


// --------------------------------------------------------------- Security


// Include the PHP-AAS requirements.
require_once("_library/framework/aas/deploy/Deploy.php");
require_once("_library/framework/aas/realm/MySQLRealm.php");


// Add MySQL authentication realm.
$realm = new MySQLRealm();
$realm->setConnectionName("jeroen");
$realm->setConnectionPassword("jeroen");
$realm->setConnectionURL("localhost/melange");
$realm->setRoleNameCol("rolename");
$realm->setUserCredCol("password");
$realm->setUserNameCol("username");
$realm->setUserRoleTable("user_role");
$realm->setUserTable("user");
$realm->setWhereClause("active=1");
//$realm->setDigest("md5");


// Add 'editor' security collection.
$collection1 = new SecurityCollection();
$collection1->setName("Editor Section");
$collection1->addPattern("/home");


// Add 'editor' constraints.
$constraint1 = new SecurityConstraint();
$constraint1->addCollection($collection1);
$constraint1->addAuthRole("admin");
$constraint1->addAuthRole("editor");


// Create a Login Configuration
$config = new LoginConfig(
    "BASIC", "MySQLRealm", "/login", "/login.php?failed"
);


// Set the security realm for this context.
$context->setRealm($realm);


// Set the loginconfig for this context.
$context->setLoginConfig($config);


// Add the 'editor' constraint for this context.
$context->addConstraint($constraint1);


// --------------------------------------------------------- Error Handling


// Add error pages.
$context->addErrorPage(
    new ErrorPage(Response::SC_UNAUTHORIZED, "/error/aas/all.php"));

$context->addErrorPage(
    new ErrorPage(Response::SC_FORBIDDEN, "/error/aas/all.php"));

$context->addErrorPage(
    new ErrorPage(Response::SC_NOT_FOUND, "/error/aas/all.php"));


// -------------------------------------------------------------------- CMS


// CMS Settings
$context->setInitParameter(_Core::I18N, true);                          // Set i18n support
$context->setInitParameter(_Core::TINY_MCE_PATH, "js/tiny_mce");        // Set path of the installed tinyMCE rich-text editor.
$context->setInitParameter(_Core::DEFAULT_LANGUAGE, "en");              // Set default language for content editing.
$context->setInitParameter(_Core::DEFAULT_LANGUAGE_NAME, "English");    // Set default language name for content editing.
$context->setInitParameter(_Core::COPYRIGHT, "Mélange");                // Set the copyright footer.
$context->setInitParameter(_Core::NAME, "Mélange CMS");                 // Set the CMS name.
$context->setInitParameter(_Core::WIDTH, "900");                        // Set the width of the CMS.
$context->setInitParameter(_Core::TEXTWIDTH, "673px");                  // Set the width of the textareas.
$context->setInitParameter(_Core::COLOR_LINK, "#0099EA");               // Set the link color. (#0099EA)
$context->setInitParameter(_Core::COLOR_HEADER, "#17A");                // Set the header color. (#17A)
$context->setInitParameter(_Content::TEMPLATE,
    "_application/resource/content.html");                              // Set the standard content template.
//$context->setInitParameter(_Core::SETTING_CATEGORY,
//    "secure:x:1:000000:282:0:x:1:000000:36:36");                        // Set the category image resize properties.
//$context->setInitParameter(_Core::SETTING_LIST,
//    "secure:x:1:000000:282:0:x:1:000000:36:36");                        // Set the list resize properties.
//$context->setInitParameter(_Content::SETTINGS,
//    "secure:x:1:000000:282:0:x:1:000000:36:36");                        // Set the content image resize properties.


// Set the core module mappings
$context->setInitParameter("config",
    "cms/core/resource/mvc-config.php");

// Set the page module mappings
$context->setInitParameter("config/content",
    "cms/content/resource/mvc-config.php");


// Add the mvc helpers (global)
$context->setInitParameter("helper/mvc/view/helper",
    "PHP_MVC_View_Helper");

$context->setInitParameter("helper/mvc/view/helper/form",
    "PHP_MVC_View_Form_Helper");


// Add the cms core helpers (global)
$context->setInitParameter("helper/cms/core/helper",
    "PHP_CMS_View_Helper");

$context->setInitParameter("helper/cms/core/helper/list",
    "PHP_CMS_View_Helper_List");

$context->setInitParameter("helper/cms/core/helper/bean",
    "PHP_CMS_View_Helper_Bean");

$context->setInitParameter("helper/cms/core/helper/form",
    "PHP_CMS_View_Helper_Form");


// ---------------------------------------------------------------- Process


// Start processing.
$context->process();


// ------------------------------------------------------- Example Settings

/**
 * Base Site URL
 *
 * URL to your Framework root. Typically this will be your base URL,
 * WITHOUT a trailing slash:
 *
 * http://www.your-site.com
 */
//$context->setInitParameter("BASE_URL", "http://imac.local:8888");


/**
 * Context path
 *
 * Path section after BASE_URL
 * WITHOUT a trailing slash
 */
//$context->setInitParameter("CONTEXT_PATH", "/framework");


/**
 * Base Framework directory
 *
 * Path to your Framework root.
 */
//$context->setInitParameter("BASE_PATH", "_library/framework");


/**
 * Default content type
 */
//$context->setInitParameter("CONTENT_TYPE", "text/xml");

?>